# 在三维坐标系中绘制两个向量
import matplotlib.pyplot as plt
import numpy as np

if __name__ == '__main__':
    # 创建一个 figure，大小根据显示器进行指定， Width, height in inches(2.54 cm).
    fig = plt.figure(figsize=(16, 9))
    # 在绘图区域中创建一个子图
    ax = fig.add_subplot(1, 1, 1, projection='3d')

    # 创建要显示的向量
    # 向量的格式：起点xyz坐标  终点 xyz 坐标
    vectors = [
        (0, 0, 0, 1, 4, 2),  # 向量1
        (0, 0, 0, 0, 3, 3),  # 向量2
    ]

    # 将向量相关信息设置到子图中
    colors = ["red", "green"]
    for i in range(len(vectors)):
        ax.quiver(
            vectors[i][0], vectors[i][1], vectors[i][2],
            vectors[i][3], vectors[i][4], vectors[i][5],
            color=colors[i],
            arrow_length_ratio=0.1,
            linewidth=2,
            label=f'Vector ({vectors[i][3]}, {vectors[i][4]}, {vectors[i][5]})'
        )

    # 设置标签
    ax.set_xlabel("X-axis", fontsize=12)
    ax.set_ylabel("Y-axis", fontsize=12)
    ax.set_zlabel("Z-axis", fontsize=12)

    # 设置xyz 轴的坐标范围
    ax.set_xlim([0, 1])
    ax.set_ylim([0, 5])
    ax.set_zlim([0, 4])

    # 设置图题
    ax.set_title('3D Vectors: (1,4,2) and (0,3,3)')

    # 关闭坐标平面底色
    ax.xaxis.pane.fill = False
    ax.yaxis.pane.fill = False
    ax.zaxis.pane.fill = False

    # 隐藏顶部和右侧边线
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)

    ax.legend()
    ax.view_init(elev=20, azim=30)

    plt.show()
